import { IPSAppDEUILogicLink, IPSDEUILogic } from '../..';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSDEUILogicLinkServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSDEUILogicLinkServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getDstPSDEUILogicNode':
      case 'getSrcPSDEUILogicNode':
        return this.getPSDELogicNode(
          relatedPSModelObject as IPSAppDEUILogicLink,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getPSDELogicNode(r: IPSAppDEUILogicLink, obj: any): any {
    if (obj.modelref) {
      const p = r
        .getParentPSModelObject()
        .getParentPSModelObject() as IPSDEUILogic;
      if (p) {
        return p.findPSDEUILogicNode(obj);
      }
    }
    return null;
  }
}
